package cheme.ProcessEditor.Figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.swt.graphics.Color;

import cheme.ProcessEditor.ChemePresentation;
import cheme.ProcessEditor.Figures.Util.TitleFig;
import cheme.ProcessEditor.Table.ListFig;
import cheme.ProcessModel.ProcessModelConstants;

public class SolvabilityStatusFig extends ListFig  
{
	private Figure light = new Ellipse();
	private Label message = new Label();
	private static final Color bgYellow  = new Color(null, 255, 255, 153);
	private static final Color bgWhite  = new Color(null, 255, 255, 255);
	
		
	public SolvabilityStatusFig(String initialMessage)
	{
		super();
		
		TitleFig title = new TitleFig("Solvability status");
		title.setToolTip(new Label("This presents the proces model solvability status."));
		add(title);
		
		setLightRed();
		light.setPreferredSize(new Dimension(10,10));
		
		Figure lightBox = new RectangleFigure();
		lightBox.setForegroundColor(ChemePresentation.TableEditors.Equations.background);
		ToolbarLayout layout = new ToolbarLayout(false);
		layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
		lightBox.setLayoutManager(layout);
		lightBox.add(light);
		add(lightBox); 
		//setLightGreen();
		setIntialLight();
		setMessage(initialMessage);
		message.setOpaque(true);
		message.setBackgroundColor(bgWhite);
		add(message);
	}
	
	private void setIntialLight() {
		light.setBackgroundColor(ColorConstants.button);
		
	}

	protected void initPresentation()
	{
		super.initPresentation();

		setPresentation(
				ChemePresentation.TableEditors.Equations.background,
				ChemePresentation.TableEditors.Equations.foreground,
				ChemePresentation.TableEditors.Equations.border
		);
	}
	
	public void setMessage(String newMessage) 
	{		
		message.setText(newMessage);
	}
	
	public void setLightRed() {
		light.setBackgroundColor(ColorConstants.red);
	}
	
	public void setLightGreen() {
		light.setBackgroundColor(ColorConstants.green);
	}

	// Set the background color of the message pane
	public void setBgColor()
	{
		if(message.getBackgroundColor()== bgWhite)
		{
			message.setBackgroundColor(bgYellow);			
			
		}
		else
		{
			message.setBackgroundColor(bgWhite);
		}
	}	
	
	// Set the Read message in the Log
	public void setLogMessage(String toolTip)
	{
		if(message.getBackgroundColor()== bgWhite)
		{	
			// log the read event.
			//ProcessModelConstants.log.Write("Read, ","Solvability Status, ", toolTip);			
		}
	}
	
}
